package ch03.shangJi.sj3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class clz = Class.forName("ch03.shangJi.sj3.Stu");
        Object o = clz.newInstance();
        Method setId = clz.getDeclaredMethod("setId", int.class);
        setId.setAccessible(true);
        setId.invoke(o,15);

        Method setName = clz.getDeclaredMethod("setName", String.class);
        setName.setAccessible(true);
        setName.invoke(o,"周周");

        Method sayHello = clz.getDeclaredMethod("sayHello");
        sayHello.invoke(o);//通过调用invoke()方法去使用实例的sayHello方法

    }
}
